/*
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Autogenerated file -- DO NOT EDIT!

#ifndef PANDA_<%= Common::module.name.upcase %>_EVENTS_GEN_H
#define PANDA_<%= Common::module.name.upcase %>_EVENTS_GEN_H

#include <fstream>

namespace <%= Common::module.namespace %> {

class Graph;

class EventWriter {
public:
    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
    EventWriter(std::string_view className, std::string_view methodName) {
        std::copy(className.begin(), className.begin() + std::min(className.size(), BUF_SIZE - 1) + 1,
                  className_.data());
        std::copy(methodName.begin(), methodName.begin() + std::min(methodName.size(), BUF_SIZE - 1) + 1,
                  methodName_.data());
    }

    static void Init(const std::string& filePath) {
        EventWriter::events_file_.open(filePath, std::ios::out);
    }

    // NOLINTBEGIN(readability-identifier-naming)
% Common::events.each do |op|
    void <%= op.method_name %>(<%= op.args_list %>) {
        events_file_ << className_.data() << "::" << methodName_.data() << ',' << "<%= op.name %>" << ',';
        <%= op.print_line %>;
        events_file_ << std::endl;
    }
% end
    // NOLINTEND(readability-identifier-naming)

public:
    // TODO (a.popov) synchronize object in multithreaded mode
    // NOLINTNEXTLINE(cert-err58-cpp,fuchsia-statically-constructed-objects,readability-identifier-naming)
    static inline std::ofstream events_file_;

private:
    static constexpr size_t BUF_SIZE = 512;
    std::array<char, BUF_SIZE> className_;
    std::array<char, BUF_SIZE> methodName_;
};

}  // namespace <%= Common::module.namespace %>

#endif  // PANDA_<%= Common::module.name.upcase %>_EVENTS_GEN_H
